﻿Imports System.Xml

Public Class frmNewReminder

    Private Sub NewReminder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DateTimePicker1.MinDate = Now.Date
        For i As Integer = 0 To 23
            ComboBox1.Items.Add(IIf(i < 10, 0, "") & i & ":" & "00-" & IIf(i < 10, 0, "") & i & ":30")
            ComboBox1.Items.Add(IIf(i < 10, 0, "") & i & ":" & "30-" & IIf(i < 10, 0, "") & i + 1 & ":00")
        Next
        ComboBox1.SelectedIndex = 0
        Me.CenterToScreen()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Hide()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim dokumen As New XmlDocument()
        Dim xElemen, xDate, xHour, xTodo As XmlElement
        Dim xFile As String = Application.StartupPath & "\Reminderxml.xml"
        Dim xNo As Integer
        With dokumen
            If Not My.Computer.FileSystem.FileExists(xFile) Then
                .LoadXml("<Reminder></Reminder>")
                xNo = 1
            Else
                .Load(xFile)
                xNo = .DocumentElement.ChildNodes.Count + 1
            End If
            xElemen = .CreateElement("Schedule")
            .DocumentElement.AppendChild(xElemen)
            Dim xId As XmlAttribute = .CreateAttribute("id")
            xId.Value = xNo
            xElemen.Attributes.Append(xId)
            xDate = .CreateElement("Date")
            xHour = .CreateElement("Hour")
            xTodo = .CreateElement("Todo")
            With xElemen
                .AppendChild(xDate)
                .AppendChild(xHour)
                .AppendChild(xTodo)
            End With
            xDate.InnerXml = Format(DateTimePicker1.Value, "dd/MM/yyyy")
            xHour.InnerXml = ComboBox1.SelectedItem
            xTodo.InnerXml = TextBox1.Text
            dokumen.Save(xFile)
            TextBox1.Clear()
            ComboBox1.SelectedIndex = 0
        End With
        frmMain.Form1_Load(sender, e)
    End Sub
End Class